package com.lovo.service;

import com.lovo.dao.InvoiceDAO;
import com.lovo.model.InvoiceDO;
import com.lovo.model.UserDO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class InvoiceService implements IInvoiceService{
    @Resource
    private UserService userService;
    @Resource
    private InvoiceDAO invoiceDAO;
    public List findAll(){
        return invoiceDAO.findAll();
    }

    @Transactional
    public void create(String userId,int amount){
        if(userService.findById(userId) == null){
            try{
                userService.insert(new UserDO("18888888888","666666"));
            }catch(Exception e){}

        }
        InvoiceDO invoiceDO = new InvoiceDO(userId,amount,"http://www.lovo.com/invoice.pdf");
        invoiceDAO.insert(invoiceDO);
        int a = 100/0;
    }
}
